package com.liss.notes.y22m02;

public class BinarySearch {
    public static int biSearch(int[] arr, int a) {
        int low = 0;
        int high = arr.length - 1;
        int mid;
        while (low <= high) {
            mid = (low + high) / 2;
            if (arr[mid] == a) {
                return mid + 1;
            } else if (arr[mid] < a) {
                low = mid + 1;
            } else {
                high = mid - 1;
            }
        }
        return -1;
    }

    public static void main(String[] args) {
        System.out.println(biSearch(new int[]{1, 2, 3, 4, 5, 6,8}, 8));
    }
}
